// Function.prototype.apply = function (scope, args) {
//     return this.call(scope, ...args);
// };

Function.prototype.apply = function (scope, arr) {
    scope = scope || window;
    var args = [];
    for (var i = 0; i < arr.length; i++) {
        var arg = arr[i];
        if (typeof arg === 'string') {
            args.push('"' + arg + '"');
        } else if (typeof arg === 'object') {
            scope['arg' + i] = arg;
            args.push('scope["arg' + i + '"]');
        } else {
            args.push(arg);
        }
    }

    scope.fn = this;
    var res = eval('scope.fn(' + args.join(',') + ')');
    delete scope.fn;
    for (var key in scope) {
        if (key.startsWith('arg')) {
            delete scope[key];
        }
    }
    return res;
};

function Foo(age, sex, options) {
    console.log(this.name);
    console.log(age);
    console.log(sex);
    console.log(options)
    return 'abcdefg'
}
var res = Foo.apply({ name: 'def' }, [45, 'man', { email: 'ss' }]);
console.log(res);